<?php

/**
 * This is the model class for table "profile".
 *
 * The followings are the available columns in table 'profile':
 * @property integer $Id
 * @property string $Lastname
 * @property string $Firstname
 * @property string $Middlename
 * @property string $Religion
 * @property integer $Sex
 * @property string $DateOfBirth
 * @property string $PlaceOfBirth
 * @property string $Address
 * @property string $ContactNumber
 * @property string $Email
 * @property string $FuturePlan
 * @property string $DateCreated
 * @property string $DateUpdate
 *
 * The followings are the available model relations:
 * @property User[] $users
 */
class Profile extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'profile';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('Lastname, Firstname, Sex, ContactNumber, Email, DateCreated', 'required'),
			array('Sex', 'numerical', 'integerOnly'=>true),
			array('Lastname, Firstname, Middlename, Religion', 'length', 'max'=>30),
			array('PlaceOfBirth', 'length', 'max'=>45),
			array('Address', 'length', 'max'=>200),
			array('ContactNumber', 'length', 'max'=>15),
			array('Email', 'length', 'max'=>100),
			array('DateOfBirth, FuturePlan, DateUpdate', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('Id, Lastname, Firstname, Middlename, Religion, Sex, DateOfBirth, PlaceOfBirth, Address, ContactNumber, Email, FuturePlan, DateCreated, DateUpdate', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'users' => array(self::HAS_MANY, 'User', 'Profile_Id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'Id' => 'ID',
			'Lastname' => 'Lastname',
			'Firstname' => 'Firstname',
			'Middlename' => 'Middlename',
			'Religion' => 'Religion',
			'Sex' => 'Sex',
			'DateOfBirth' => 'Date Of Birth',
			'PlaceOfBirth' => 'Place Of Birth',
			'Address' => 'Address',
			'ContactNumber' => 'Contact Number',
			'Email' => 'Email',
			'FuturePlan' => 'Future Plan',
			'DateCreated' => 'Date Created',
			'DateUpdate' => 'Date Update',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('Id',$this->Id);
		$criteria->compare('Lastname',$this->Lastname,true);
		$criteria->compare('Firstname',$this->Firstname,true);
		$criteria->compare('Middlename',$this->Middlename,true);
		$criteria->compare('Religion',$this->Religion,true);
		$criteria->compare('Sex',$this->Sex);
		$criteria->compare('DateOfBirth',$this->DateOfBirth,true);
		$criteria->compare('PlaceOfBirth',$this->PlaceOfBirth,true);
		$criteria->compare('Address',$this->Address,true);
		$criteria->compare('ContactNumber',$this->ContactNumber,true);
		$criteria->compare('Email',$this->Email,true);
		$criteria->compare('FuturePlan',$this->FuturePlan,true);
		$criteria->compare('DateCreated',$this->DateCreated,true);
		$criteria->compare('DateUpdate',$this->DateUpdate,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Profile the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
